package com.dotflat.util;

import com.dotflat.util.excelUtil.StringUtils;

public class AccessControlUserIdUtil {
    public static long strToLng(String strVal) {
        long V_0 = 0;
        try {
            String V_1 = String.format("%-8s", strVal).replace(' ', '0');
            String[] V_4 = new String[5];
            V_4[0] = "";  //for &h
            V_4[1] = strVal.substring(V_1.length() - 2);
            V_4[2] = strVal.substring(V_1.length() - 4, V_1.length() - 2);
            V_4[3] = strVal.substring(V_1.length() - 6, V_1.length() - 4);
            V_4[4] = strVal.substring(V_1.length() - 8, V_1.length() - 6);

            String concatStr = String.join("", V_4);
            int result = Integer.parseInt(concatStr, 16);
            V_0 = result;
        } catch (Exception ex) {
            throw ex;
        }
        return V_0;
    }

    public static long GetCardId(String uid)
    {
        if (StringUtils.equals("",uid)){
            return 0l;
        }
        //8位卡号，截取6位再转换
        String uidSubString = uid.substring(0, 6);
        long cardNo = strToLng(uidSubString);
        long p1 = cardNo >> 16;
        long p2 = p1 << 16;
        long p3 = cardNo - p2;
        long cardId = p1 * 100000 + p3;
        return cardId;
    }
}
